package lobby
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import lobby.events.LobbyEvent;
	import lobby.exchangeddata.TransactionItemInfo;
	
	/**
	 * ...
	 * @author Bamboo
	 */
	public class TransactionItem extends MovieClip
	{
		public var txtTransactionNoTf:TextField;
		public var txtTransactionIdTf:TextField;
		public var txtTransactionTypeTf:TextField;
		public var txtTransactionResultDateTf:TextField;
		public var txtTransactionTableTf:TextField;
		public var txtTransactionGameTf:TextField;
		public var txtTransactionResultTf:TextField;
		public var txtTransactionBetCodeTf:TextField;
		public var txtTransactionAmountTf:TextField;
		public var txtTransactionBalanceTf:TextField;
		public var txtTransactionCommTf:TextField;
		
		public var btnGetDetail:MovieClip;
		
		public function TransactionItem(value:TransactionItemInfo, odd:Boolean)
		{
			trace("value.getTransactionNo : " + value.getTransactionNo);
			if (value.getTransactionNo != "")
			{
				this.txtTransactionNoTf.text = value.getTransactionNo;
				this.txtTransactionIdTf.text = value.getTransactionId;
				this.txtTransactionTypeTf.text = value.getTransactionType;
				this.txtTransactionResultDateTf.text = value.getTransactionResultDate;
				this.txtTransactionTableTf.text = value.getTransactionTable;
				this.txtTransactionGameTf.text = value.getTransactionGame;
				this.txtTransactionResultTf.text = value.getTransactionResult;
				this.txtTransactionBetCodeTf.text = value.getTransactionBetCode;
				this.txtTransactionAmountTf.text = value.getTransactionAmount;
				formatAmount(value.getTransactionAmount, this.txtTransactionAmountTf, 0xFF0000);
				this.txtTransactionBalanceTf.text = value.getTransactionBalance;
				this.txtTransactionCommTf.text = value.getTransactionComm;
			}
			btnGetDetail.visible = odd;
			btnGetDetail.buttonMode = odd;
			btnGetDetail.addEventListener(MouseEvent.CLICK, hldClick);
			if (odd)
			{
				colorFormat(this.txtTransactionIdTf, 0x009900);
			}
			else
			{
				
				colorFormat(this.txtTransactionIdTf, 0xFFFFFF);
			}
		}
		
		private function hldClick(e:MouseEvent):void
		{
			var evt:LobbyEvent = new LobbyEvent(LobbyEvent.GET_TRANSACTION_DETAIL, true);
			evt.ms = txtTransactionIdTf.text;
			dispatchEvent(evt);
		}
		
		private function formatAmount(value:String, txtTf:TextField, color:uint):void
		{
			var amount:Number = Number(value);
			if (amount < 0)
			{
				colorFormat(txtTf, color);
			}
		}
		
		private function colorFormat(txtTf:TextField, color:uint):void
		{
			var format:TextFormat = new TextFormat();
			format.color = color;
			txtTf.setTextFormat(format);
		
		}
	}

}